<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // async await是有传染性的 —— 当一个函数变为async后，这意味着调用他的函数也需要是async
        var p1fn = () => new Promise((res, rej) => setTimeout(() => { res('1s') }, 500))
        var p2fn = () => new Promise((res, rej) => setTimeout(() => { res('1s') }, 500))

        var p3fn = () => new Promise((res, rej) => setTimeout(() => { res('1s') }, 500))
        var p4fn = () => new Promise((res, rej) => setTimeout(() => { res('1s') }, 500))

        async function fn1() {
            console.time('a')
            const result1 = await p1fn()
            console.timeEnd('a')
            console.time('b')
            const result2 = await p2fn()
            console.timeEnd('b')
        }


        async function fn2() {
            console.time('c')
            const result1 = await p3fn()
            console.timeEnd('c')
            console.time('d')
            const result2 = await p4fn()
            console.timeEnd('d')
        }
        async function resultFn(){
            await fn1()
            await fn2()
        }

        resultFn()
    </script>
</body>

</html>